<template>
  <div>
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">{{ $t('m.common.button.add') }}</a-button>
      <a-button @click="batchDel" type="default"  icon="delete">{{ $t('m.common.button.delete') }}</a-button>

      <div style="float: right">
        <a-input-search style="width: 200px;" :placeholder="$t('m.common.label.guan-jian-zi')" enter-button @search="onSearch"></a-input-search>
      </div>
    </div>

    <!-- table区域-begin -->
    <a-table
      ref="table"
      size="middle"
      bordered
      rowKey="id"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :loading="loading"
      :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
      @change="handleTableChange"
    >
      <template slot="serialNum" slot-scope="text,record,index">
        {{(ipagination.current-1) * ipagination.pageSize + parseInt(index) + 1}}
      </template>
      <template slot="action" slot-scope="text, record">
        <a @click="handleEdit(record)">{{ $t('m.common.button.update') }}</a>
        <a-divider type="vertical"/>
        <a @click="generatorCode(record)">{{$t('m.eform.apptable.other.source_gen')}}</a>
        <a-divider type="vertical"/>
        <a-popconfirm :title="$t('m.common.tip.delete_confirm')" @confirm="() => handleDelete(record.id)">
          <a>{{ $t('m.common.button.delete') }}</a>
        </a-popconfirm>
      </template>

    </a-table>

    <actAppObject-modal ref="modalForm" @ok="modalFormOk" :groupId="groupId"/>
    <CodegenConfigDialog ref="codegenConfigDialog" @refreshParent="modalFormOk"/>
  </div>
</template>

<script>

  import { YcListMixin } from '@/mixins/YcListMixin'
  import { filterMultiDictText } from '@/components/dict/YchDictSelectUtil'
  import ActAppObjectModal from './modules/ActAppObjectModal'
  import { EFormConstant } from './EFormConstant'
  import CodegenConfigDialog from '../codegen/genconfig/modules/CodegenConfigDialog'
  import YchConstant from "@/api/YchConstant";

  export default {
    name: 'ActAppObjectList',
    mixins: [YcListMixin],
    components: {
      ActAppObjectModal,
      CodegenConfigDialog
    },
    props: {
      groupId: {
        type: String,
        required: true
      },
    },
    data () {
      return {
        queryParam: {
          groupId: this.groupId
        },
        isorter: {
          column: 'orderNum',
          order: 'asc',
        },
        columns: [
          {
            title:this.$t('m.common.label.number'),
            dataIndex: '',
            key: 'rowIndex',
            width: 50,
            align: 'center',
            scopedSlots: { customRender: 'serialNum' },
          },
          {
            title: this.$t('m.eform.apptable.entity.objName'),
            align: 'center',
            dataIndex: 'objName'
          },
          {
            title: this.$t('m.eform.apptable.entity.objCode'),
            align: 'center',
            dataIndex: 'objCode'
          },
          /*{
            title: '持久化方式',
            align: 'center',
            dataIndex: 'persistenceType',
            customRender: (text) => {
              if (!text) {
                return ''
              } else {
                return filterMultiDictText(EFormConstant.persistenceType, text + '')
              }
            }
          },*/
          {
            title: this.$t('m.eform.apptable.entity.objStructure'),
            align: 'center',
            dataIndex: 'objStructure',
            customRender: (text) => {
              if (!text) {
                return ''
              } else {
                return filterMultiDictText(EFormConstant.objStructure, text + '')
              }
            }
          },
          {
            title: this.$t('m.common.label.sort'),
            align: 'center',
            dataIndex: 'orderNum',
            width: 80,
          },
          {
            title: this.$t('m.common.label.operate'),
            dataIndex: 'action',
            align: 'center',
            width: 300,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: YchConstant.PREFIX_EFORM + '/manage/actAppObject/list',
          delete: YchConstant.PREFIX_EFORM + '/manage/actAppObject/delete',
          deleteBatch: YchConstant.PREFIX_EFORM + '/manage/actAppObject/deleteBatch',
        }
      }
    },
    methods: {
      generatorCode(recode){
        this.$refs.codegenConfigDialog.add(recode.objCode)
      },
    }
  }
</script>
<style lang="less" scoped>
</style>
